goog.require('dkpoints.raid.RaidDriver');
goog.require('dkpoints.tests.stubFn');


var bodyContent, stubFn, realNewRaidView;
function setUpPage() {
  bodyContent = document.getElementById('body_content');
  realNewRaidView = dkpoints.raid.NewRaidView;
  stubFn = dkpoints.tests.stubFn;
}


var rpc, status, driver;
function setUp() {
  rpc = {
    execute: stubFn()
  };
  status = {};
  driver = new dkpoints.raid.RaidDriver(rpc, status, bodyContent);
}


/**
 * Test that the RaidDriver constructor stores references to its dependencies
 * and sets its appropriate defaults.
 */
var testConstructorStoresDependenciesAndSetsDefaults = function() {
  assertEquals('driver.rpc_ should be the given rpc object.',
               rpc, driver.rpc_);
  assertEquals('driver.status_ should be the given status object.',
               status, driver.status_);
  assertEquals('driver.bodyContent_ should be the given bodyContent element.',
               bodyContent, driver.bodyContent_);
  assertFalse('driver.active_ should be set to false on construction.',
              driver.active_);
  assertEquals('driver.editableState_ should be READ_ONLY by default.',
               dkpoints.raid.RaidDriver.State.READ_ONLY, driver.editableState_);
};


/**
 * Test that createNewRaid sets driver.editableState_ to EDITABLE.
 */
var testCreateNewRaidSetsStateToEditable = function() {
  var newRaidView = dkpoints.raid.NewRaidView = stubFn();
  driver.createNewRaid();
  assertEquals('driver.editableState_ should be EDITABLE.',
               dkpoints.raid.RaidDriver.State.EDITABLE, driver.editableState_);
};


/**
 * Test that createNewRaid creates a new NewRaidView and stores it in
 * driver.view_.
 */
var testCreateNewRaidCreatesNewRaidView = function() {
  var newRaidView = dkpoints.raid.NewRaidView = stubFn();
  driver.createNewRaid();
  assertTrue('driver.createNewRaid should have called `new NewRaidView`.',
             newRaidView.called);
  assertTrue('driver.view_ should be an instance of our mock NewRaidView.',
             driver.view_ instanceof newRaidView);
};


function tearDown() {
  bodyContent.innerHTML = '';
  rpc = status = driver = null;
  dkpoints.raid.NewRaidView = realNewRaidView;
}
